package com.csxy.dyq.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.csxy.dyq.R;
import com.csxy.dyq.entity.EduCourse;
import com.csxy.dyq.entity.vo.ChapterVo;
import com.csxy.dyq.entity.vo.CourseFrontVo;
import com.csxy.dyq.entity.vo.CourseInfoForm;
import com.csxy.dyq.entity.vo.CourseWebVo;
import com.csxy.dyq.service.EduChapterService;
import com.csxy.dyq.service.EduCourseService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/eduservice/coursefront")
public class CourseFrontController {

    @Autowired
    private EduCourseService eduCourseService;
    @Autowired
    private EduChapterService chapterService;

    @PostMapping("getFrontCourseList/{page}/{limit}")
    public R getFrontCourseList(@PathVariable long page, @PathVariable long limit,
                                @RequestBody(required = false) CourseFrontVo courseFrontVo) {
        Page<EduCourse> pageCourse = new Page<>(page, limit);
        Map<String, Object> map = eduCourseService.getCourseFrontInfo(pageCourse, courseFrontVo);
        return R.ok().data(map);
    }
    //2 获取课程详情方法
    @GetMapping("getFrontCourseInfo/{courseId}")
    public R getFrontCourseInfo(@PathVariable String courseId, HttpServletRequest  request) {
        //1 根据课程id，编写sql语句查询课程信息
        CourseInfoForm courseWebVo = eduCourseService.getBaseCourseInfo(courseId);
        //
        List<ChapterVo> chapterVoList = chapterService.getChapterVideoByCourseId(courseId);
        return R.ok().data("courseWebVo", courseWebVo).data("chapterVoList", chapterVoList);
    }
}

